import Vue from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'
import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';
import './assets/css/flex.css'
import Fragment from 'vue-fragment'
import axios from 'axios';
import http from './utils/axios/api'
import 'vx-easyui/dist/themes/default/easyui.css';
import 'vx-easyui/dist/themes/icon.css';
import 'vx-easyui/dist/themes/vue.css';
import EasyUI from 'vx-easyui';
Vue.use(EasyUI);
Vue.use(Fragment.Plugin)
Vue.use(ElementUI);

Vue.config.productionTip = false;
Vue.prototype.$http = http;


// axios.interceptors.request.use(config => {
//   if (config.url.indexOf("/api/pub/login") != -1) {
//     //以multipart/form-data形式提交
//     config.headers['Content-Type'] = 'multipart/form-data'
//   } else {
//     //以json形式提交
//     config.headers['Content-Type'] = 'application/json'
//   }
//   return config;
// })


axios.interceptors.response.use(
  response => {
    console.log(response);
    if (response.data.code !== 0) {  //请求发生出错
      // 当请求时用户没有登录
      if(response.data.code==-1){
        router.push("/login");
      }
      console.log("请求错误", response.data.msg);
      return response;
    } 
    return response;
  },
  error => {  //404或500这种错误时触发
    // console.log("err12344", error)// for debug
    return Promise.reject(error);  //返回promise错误
  });
new Vue({
  router,
  store,
  render: h => h(App)
}).$mount('#app')
